<html>
<head><meta charset="utf-8"><title>There are no zero-cost abstractions · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html">There are no zero-cost abstractions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178729902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/178729902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#178729902">(Oct 22 2019 at 07:28)</a>:</h4>
<p>Interesting talk on abstractions in C++ by Chandler, in particular the part about <code>unique_ptr</code> starting at <a href="https://youtu.be/rHIkrotSwcc?t=1053" target="_blank" title="https://youtu.be/rHIkrotSwcc?t=1053">https://youtu.be/rHIkrotSwcc?t=1053</a>.<br>
From what I understand, Rust doesn't have this problem, right? Our <code>Box</code> is <code>repr(transparent)</code> (I would not have expected that to make such a big difference, nice to see examples of the kind of code it avoids) and we have destructive moves.</p>
<div class="youtube-video message_inline_image"><a data-id="rHIkrotSwcc" href="https://youtu.be/rHIkrotSwcc?t=1053" target="_blank" title="https://youtu.be/rHIkrotSwcc?t=1053"><img src="https://i.ytimg.com/vi/rHIkrotSwcc/default.jpg"></a></div>



<a name="178738633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/178738633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#178738633">(Oct 22 2019 at 09:41)</a>:</h4>
<p>Lol no we don't have this problem. We have other problems where we don't actually optimize our abstractions to be zero cost, but boxes aren't one of these problems</p>



<a name="178742961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/178742961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#178742961">(Oct 22 2019 at 10:46)</a>:</h4>
<p>I can't read the assembly right now, but panic handling seems to have some overhead here: <a href="https://rust.godbolt.org/z/n7d-Li" target="_blank" title="https://rust.godbolt.org/z/n7d-Li">https://rust.godbolt.org/z/n7d-Li</a></p>



<a name="178743217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/178743217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#178743217">(Oct 22 2019 at 10:50)</a>:</h4>
<p>I'm surprised that <code>alloc::alloc::box_free</code> and <code>example::baz</code> don't get folded</p>



<a name="178743288"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/178743288" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#178743288">(Oct 22 2019 at 10:51)</a>:</h4>
<p>And how is the code at the end of <code>foo</code> reached (the <code>_Unwind_Resume</code> block)?</p>



<a name="179014949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/179014949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> atagunov <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#179014949">(Oct 25 2019 at 01:33)</a>:</h4>
<p>@Laurențiu Nicola : <code>example:baz</code> not folded likely due to <code>#[inline(never)]</code><br>
<code>box_free</code> only called from panic path.. so LLVM decided not to inline?</p>
<p>however I share your surprise at the main question: how would the panic unwind path be hit?..<br>
that <code>_Unwind_Resume</code> must be magic :)</p>



<a name="179015949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/179015949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#179015949">(Oct 25 2019 at 01:59)</a>:</h4>
<p>IIRC, at least on linux, the standard way is to encode via DWARF an unwind table that says where to jump to based on current stack layout (including the ability to do arbitrary operations on registers/memory to "unwind" to the appropriate place)</p>



<a name="179015955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/179015955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#179015955">(Oct 25 2019 at 01:59)</a>:</h4>
<p>(this is how exceptions in C++ work as well as our panics, or backtrace gathering for example)</p>



<a name="179016004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/179016004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#179016004">(Oct 25 2019 at 02:00)</a>:</h4>
<p>I'm not sure how windows does it -- but probably something somewhat similar</p>



<a name="179024644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/There%20are%20no%20zero-cost%20abstractions/near/179024644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/There.20are.20no.20zero-cost.20abstractions.html#179024644">(Oct 25 2019 at 06:11)</a>:</h4>
<p>But <code>box_free</code> is also <code>#[inline]</code>.. Good point about the unwinding, though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>